<template>
  <div id="detail">
        <div class="main-bar-view">
            <img src="../assets/images/logo.png" class="logo" @click="returnTo">
            <div class="search-entry">
                <img src="../assets/images/search-icon.svg" class="search-icon">
                <input placeholder="请输入搜索的内容">
            </div>
            <div class="right-view">
                <a class="ant-dropdown-link ant-dropdown-trigger" v-if="isLogged">
                  <img src="../assets/images/avatar.jpg" class="self-img">
                </a>
                <button class="login btn hidden-sm" @click="toLoginPage" v-else>登录</button>
                <div class="right-icon">
                    <img src="../assets/images/message-icon.svg">
                </div>
            </div>
        </div>
        <div class="content">
            <div style="position: relative;">
                <div class="book-infos-view">
                    <div class="book-infos">
                        <div class="book-img-box">
                            <img :src="processedCoverPath">
                        </div>
                        <div class="book-info-box">
                            <h1 class="book-name">{{ this.novelName }}</h1>
                            <div class="authors flex-view">
                                <span>作者：</span>
                                <span class="name">{{ this.detailData.author }}</span>
                            </div>
                            <br>
                            <div class="translators flex-view">
                                <span>分类：</span>
                                <span class="name">{{ this.category }}</span>
                            </div>
                            <br>
                            <div class="translators flex-view">
                                <span class="name">{{ this.detailData.latestChapter }}</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="flex-view">
                    <div class="buy-way-item">
                        <div class="price">
                            <button class="buy-btn" @click="onlineRead">
                                <span>在线阅读</span>
                            </button>
                        </div>
                    </div>
                </div>
                <div class="detail-content-bottom">
                    <div class="main-content">
                        <div class="order-view">
                            <span class="tab tab-select">
                                简介
                            </span>
                            <span class="tab-underline" style="left: 6px;">
                            </span>
                        </div>
                        <div class="book-intro">
                            <p class="text">
                              {{ this.detailData.syn }}
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import axios from "axios";
import Cookies from 'js-cookie';
export default {
  name : 'novelView',
  data() {
    return {
      novelName: undefined,
      category: undefined,
      detailData: undefined,
    }
  },
  mounted() {
    this.novelName = this.$route.params.novelName;
    try {
    console.log(this.novelName);
} catch (error) {
    console.log("出错了");
}
    this.getNovelDetail();
  },
  methods:{
    getNovelDetail(){
      axios.post('http://127.0.0.1:5000/v1/booksOnline/getBookInfo',
          {
            'novelName':this.novelName,
          },{headers: { 'Content-Type': 'application/json' }})
          .then(response => {
             if(response.data.status === 200){
              this.detailData = response.data.data;
              this.category = response.data.msg;
              console.log(this.detailData);
            }
            else {
              alert('no such book');
            }
          })
    },
    toLoginPage(){
      this.$router.push('/login')
    },
    onlineRead(){
      window.location.href = this.detailData.link;
    },
    returnTo(){
      this.$router.push({name: 'userborrowview'})
    },
  },
  computed:{
    processedCoverPath() {
       if (this.detailData) {
      return "http://127.0.0.1:5000/static/onlineread/" + this.category + '图片/' +this.novelName + '.jpg';
    } else {
      // 返回一个默认值或者空字符串，取决于你的需求
      return "http://127.0.0.1:5000/static/1.jpg";
    }
    },
    isLogged(){
      const token = Cookies.get('token');
      console.log(token)
      const isLogged = token !== undefined && token !== '';
      console.log(isLogged)
      return isLogged;
    }
  }
}
</script>

<style scoped lang="less">
.main-bar-view {
    position: fixed;
    top: 0;
    left: 0;
    height: 56px;
    width: 100%;
    background: #fff;
    border-bottom: 1px solid #cedce4;
    padding-left: 48px;
    z-index: 16;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -ms-flex-direction: row;
    flex-direction: row;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
}
.main-bar-view .logo {
    width: 30px;
    height: auto;
    margin-right: 24px;
}
.search-entry {
    display: flex;
    position: relative;
    width: 400px;
    min-width: 200px;
    height: 32px;
    background: #ecf3fc;
    padding: 0 12px;
    border-radius: 16px;
    font-size: 0;
    cursor: pointer;
}
.search-entry .search-icon{
  justify-content: flex-start;
    width: 18px;
    margin: 7px 8px 0 0;
}
.search-entry img{
  justify-content: flex-start;

    max-width: 100%;
    height: auto;
}
.search-entry input{
    position: absolute;
    top: 4px;
    width: auto;
    height: 24px;
    border: 0;
    outline: none;
    color: #000;
    background: #ecf3fc;
    font-size: 14px;
}
.right-view{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0,0,0,.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    padding-right: 80px;
    -webkit-box-flex: 1;
    flex: 1;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    flex-direction: row;
    gap: 20px;
    -webkit-box-pack: end;
    justify-content: flex-end;

}
.self-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    vertical-align: middle;
    cursor: pointer;
  }
a{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    font-size: 14px;
    font-variant: tabular-nums;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    color: #1890ff;
    text-decoration: none;
    background-color: transparent;
    outline: none;
    cursor: pointer;
    transition: color .3s;
    touch-action: manipulation;
    line-height: 32px;
    width: 60px;

}
.right-view .btn {
    background: #4684e2;
    font-size: 14px;
    color: #fff;
    border-radius: 32px;
    text-align: center;
    width: 66px;
    height: 32px;
    line-height: 32px;
    vertical-align: middle;
    margin-left: 32px;
}
.right-view button {
    outline: none;
    border: none;
    cursor: pointer;
}
.right-view img[data-v-97d8b1e2] {
    cursor: pointer;
}
.right-view .right-icon img{
    margin-right: 20px;
    position: relative;
    width: 24px;
    margin: 4px 0 0 4px;
    cursor: pointer;
    display: inline-block;
    font-size: 0;
}
#detail {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0,0,0,.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    box-sizing: border-box;
    font-family: Avenir,Helvetica,Arial,sans-serif;
    height: 100vh;
}
.book-infos-view{
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    margin: 89px 0 40px;
    overflow: hidden;
}
.book-infos-view .book-infos{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0,0,0,.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    -webkit-box-flex: 1;
    flex: 1;
    display: flex;

  .book-img-box{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0,0,0,.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    -webkit-box-flex: 0;
    flex: 0 0 235px;
    margin: 0 40px 0 0;

  img{
    width:250px
  }
  }
  .book-info-box{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0,0,0,.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    text-align: left;
    padding: 0;
    margin: 0;

  .book-name{
    font-size: 24px;
    line-height: 32px;
    margin: 16px 0;
  }
  }
}
.flex-view{
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;

  .buy-way-item {
    background: #fbfeff;
    border: 1px solid #cedce4;
    border-radius: 4px;
    -webkit-box-flex: 0;
    margin-right: 20px;
    -ms-flex: 0 0 255px;
    flex: 0 0 255px;
    padding: 10px;

    .name {
      font-weight: 500;
      font-size: 18px;
      line-height: 24px;
      color: #152844;
      height: 24px;
      margin-bottom: 12px;
      margin-left: 4px;
      text-align: left;
    }

    .price {
      position: relative;
      line-height: 24px;

      .buy-btn {
      cursor: pointer;
      display: block;
      background: #4684e2;
      border-radius: 4px;
      text-align: center;
      color: #fff;
      font-size: 14px;
      height: 32px;
      line-height: 32px;
      width: 76px;
      outline: none;
      border: none;
      margin-top: 12px;
    }

    .buy-btn img {
      width: 12px;
      margin-right: 2px;
      vertical-align: middle;
    }

    .buy-btn span {
      vertical-align: middle;
    }
    }

    .price-text {
      color: #ff7b31;
      font-size: 18px;
      font-weight: 700;
    }


  }
}

.content{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0,0,0,.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    flex-direction: column;
    width: 1100px;
    margin: 4px auto;
}
.main-content{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0,0,0,.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    -webkit-box-flex: 1;
    flex: 1;
}
.detail-content-bottom{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    color: rgba(0,0,0,.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    margin-top: 30px;
}
.order-view{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    font-variant: tabular-nums;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    box-sizing: border-box;
    border-bottom: 1px solid #cedce4;
    position: relative;
    color: #6c6c6c;
    font-size: 14px;
    line-height: 40px;
}
.tap{
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    --antd-wave-shadow-color: #1890ff;
    font-variant: tabular-nums;
    font-feature-settings: "tnum";
    font-family: Avenir,Helvetica,Arial,sans-serif;
    color: #6c6c6c;
    font-size: 14px;
    line-height: 40px;
}

</style>